<?php

class m_flowdetchecklist extends CI_Model{
	
	function _list($data){
		extract($data);
		$sql = "SELECT 
					m_flowdet_id,
					m_checklist_id,
					flowdetchecklist_id
				FROM m_flowdetchecklist
				WHERE 
					flowdetchecklist_active = 'y'
		";
		
		if (@$m_flowdet_id != "") $sql .= " AND m_flowdet_id like '%".@$m_flowdet_id."%'";
		if (@$m_checklist_id != "") $sql .= " AND m_checklist_id like '%".@$m_checklist_id."%'";
		
		$query = $this->db->query($sql);
		$records = $query->num_rows();
		
		$sql = "SELECT * FROM (".$sql.") k LIMIT ".(($page - 1) * $rows).",".$rows;
		$query = $this->db->query($sql);
		$result = $query->result();
		
		return '{ 
		  "total": "'.ceil($records / $rows).'", 
		  "page": "'.$page.'", 
		  "records": "'.$records .'",
		  "rows" : '.json_encode($result).'
		}';
	}
	
	function _insert($data){
		$this->db->insert('m_flowdetchecklist',$data);
		return 1;
	}
	
	function _update($data,$id){
		$this->db->where('flowdetchecklist_id',$id);
		$this->db->update('m_flowdetchecklist',$data);
		return 1;
	}
	
	function _delete($data,$id){
		$this->db->where('flowdetchecklist_id',$id);
		$this->db->update('m_flowdetchecklist',$data);
		return 1;
	}
}